home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 November / PCWNOV07.iso / Software / Freeware / NSIS 2.29 / nsis-2.29-setup.exe / Examples / waplugin.nsi < prev    next >
Encoding:
Text File  |  2005-07-09  |  4.5 KB  |  202 lines

  1. ; waplugin.nsi
  2. ;
  3. ; This script will generate an installer that installs a Winamp 2 plug-in.
  4. ;
  5. ; This installer will automatically alert the user that installation was
  6. ; successful, and ask them whether or not they would like to make the 
  7. ; plug-in the default and run Winamp.
  8.  
  9. ;--------------------------------
  10.  
  11. ; Uncomment the next line to enable auto Winamp download
  12. ; !define WINAMP_AUTOINSTALL
  13.  
  14. ; The name of the installer
  15. Name "TinyVis Plug-in"
  16.  
  17. ; The file to write
  18. OutFile "waplugin.exe"
  19.  
  20. ; The default installation directory
  21. InstallDir $PROGRAMFILES\Winamp
  22.  
  23. ; detect winamp path from uninstall string if available
  24. InstallDirRegKey HKLM \
  25.                  "Software\Microsoft\Windows\CurrentVersion\Uninstall\Winamp" \
  26.                  "UninstallString"
  27.  
  28. ; The text to prompt the user to enter a directory
  29. DirText "Please select your Winamp path below (you will be able to proceed when Winamp is detected):"
  30. # currently doesn't work - DirShow hide
  31.  
  32. ; automatically close the installer when done.
  33. AutoCloseWindow true
  34.  
  35. ; hide the "show details" box
  36. ShowInstDetails nevershow
  37.  
  38. ;--------------------------------
  39.  
  40. ;Pages
  41.  
  42. Page directory
  43. Page instfiles
  44.  
  45. ;--------------------------------
  46.  
  47. ; The stuff to install
  48.  
  49. Section ""
  50.  
  51. !ifdef WINAMP_AUTOINSTALL
  52.   Call MakeSureIGotWinamp
  53. !endif
  54.  
  55.   Call QueryWinampVisPath
  56.   SetOutPath $1
  57.  
  58.   ; File to extract
  59.   #File "C:\program files\winamp\plugins\vis_nsfs.dll"
  60.   File /oname=vis_nsfs.dll "${NSISDIR}\Plugins\TypeLib.dll" # dummy plug-in
  61.  
  62.   ; prompt user, and if they select no, go to NoWinamp
  63.   MessageBox MB_YESNO|MB_ICONQUESTION \
  64.              "The plug-in was installed. Would you like to run Winamp now with TinyVis as the default plug-in?" \
  65.              IDNO NoWinamp
  66.     WriteINIStr "$INSTDIR\Winamp.ini" "Winamp" "visplugin_name" "vis_nsfs.dll"
  67.     WriteINIStr "$INSTDIR\Winamp.ini" "Winamp" "visplugin_num" "0"
  68.     Exec '"$INSTDIR\Winamp.exe"'
  69.   NoWinamp:
  70.   
  71. SectionEnd
  72.  
  73. ;--------------------------------
  74.  
  75. Function .onVerifyInstDir
  76.  
  77. !ifndef WINAMP_AUTOINSTALL
  78.  
  79.   ;Check for Winamp installation
  80.  
  81.   IfFileExists $INSTDIR\Winamp.exe Good
  82.     Abort
  83.   Good:
  84.  
  85. !endif ; WINAMP_AUTOINSTALL
  86.  
  87. FunctionEnd
  88.  
  89. Function QueryWinampVisPath ; sets $1 with vis path
  90.  
  91.   StrCpy $1 $INSTDIR\Plugins
  92.   ; use DSPDir instead of VISDir to get DSP plugins directory
  93.   ReadINIStr $9 $INSTDIR\winamp.ini Winamp VisDir 
  94.   StrCmp $9 "" End
  95.   IfFileExists $9 0 End
  96.     StrCpy $1 $9 ; update dir
  97.   End:
  98.   
  99. FunctionEnd
  100.  
  101. !ifdef WINAMP_AUTOINSTALL
  102.  
  103. Function GetWinampInstPath
  104.  
  105.   Push $0
  106.   Push $1
  107.   Push $2
  108.   ReadRegStr $0 HKLM \
  109.      "Software\Microsoft\Windows\CurrentVersion\Uninstall\Winamp" \ 
  110.      "UninstallString"
  111.   StrCmp $0 "" fin
  112.  
  113.     StrCpy $1 $0 1 0 ; get firstchar
  114.     StrCmp $1 '"' "" getparent 
  115.       ; if first char is ", let's remove "'s first.
  116.       StrCpy $0 $0 "" 1
  117.       StrCpy $1 0
  118.       rqloop:
  119.         StrCpy $2 $0 1 $1
  120.         StrCmp $2 '"' rqdone
  121.         StrCmp $2 "" rqdone
  122.         IntOp $1 $1 + 1
  123.         Goto rqloop
  124.       rqdone:
  125.       StrCpy $0 $0 $1
  126.     getparent:
  127.     ; the uninstall string goes to an EXE, let's get the directory.
  128.     StrCpy $1 -1
  129.     gploop:
  130.       StrCpy $2 $0 1 $1
  131.       StrCmp $2 "" gpexit
  132.       StrCmp $2 "\" gpexit
  133.       IntOp $1 $1 - 1
  134.       Goto gploop
  135.     gpexit:
  136.     StrCpy $0 $0 $1
  137.  
  138.     StrCmp $0 "" fin
  139.     IfFileExists $0\winamp.exe fin
  140.       StrCpy $0 ""
  141.   fin:
  142.   Pop $2
  143.   Pop $1
  144.   Exch $0
  145.   
  146. FunctionEnd
  147.  
  148. Function MakeSureIGotWinamp
  149.  
  150.   Call GetWinampInstPath
  151.   
  152.   Pop $0
  153.   StrCmp $0 "" getwinamp
  154.     Return
  155.     
  156.   getwinamp:
  157.   
  158.   Call ConnectInternet ;Make an internet connection (if no connection available)
  159.   
  160.   StrCpy $2 "$TEMP\Winamp Installer.exe"
  161.   NSISdl::download http://download.nullsoft.com/winamp/client/winamp281_lite.exe $2
  162.   Pop $0
  163.   StrCmp $0 success success
  164.     SetDetailsView show
  165.     DetailPrint "download failed: $0"
  166.     Abort
  167.   success:
  168.     ExecWait '"$2" /S'
  169.     Delete $2
  170.     Call GetWinampInstPath
  171.     Pop $0
  172.     StrCmp $0 "" skip
  173.     StrCpy $INSTDIR $0
  174.   skip:
  175.   
  176. FunctionEnd
  177.  
  178. Function ConnectInternet
  179.  
  180.   Push $R0
  181.     
  182.     ClearErrors
  183.     Dialer::AttemptConnect
  184.     IfErrors noie3
  185.     
  186.     Pop $R0
  187.     StrCmp $R0 "online" connected
  188.       MessageBox MB_OK|MB_ICONSTOP "Cannot connect to the internet."
  189.       Quit
  190.     
  191.     noie3:
  192.   
  193.     ; IE3 not installed
  194.     MessageBox MB_OK|MB_ICONINFORMATION "Please connect to the internet now."
  195.     
  196.     connected:
  197.   
  198.   Pop $R0
  199.   
  200. FunctionEnd
  201.  
  202. !endif ; WINAMP_AUTOINSTALL